package com.whiteape.book.ui.adapter;

import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.whiteape.book.R;
import com.whiteape.book.core.page.PageStyleNew;

import java.util.List;

/**
 * 背景色、前景色
 */
public class ReadSettingColorStyleAdapter extends BaseQuickAdapter<PageStyleNew, BaseViewHolder> {

    //bg selected
    private PageStyleNew selected;
    public ReadSettingColorStyleAdapter(int layoutResId, @Nullable List<PageStyleNew> data) {
        super(layoutResId, data);
    }

    public void setSelected(PageStyleNew selected) {
        this.selected = selected;
    }

    public PageStyleNew getSelected(){
        return selected;

    }

    @Override
    protected void convert(BaseViewHolder helper, PageStyleNew item) {
        helper.setTextColor(R.id.tv_content, Color.parseColor(item.getFontColor()));
        if(item.getBgColor().startsWith("#")) {
            helper.setImageDrawable(R.id.image_view, new ColorDrawable(Color.parseColor(item.getBgColor())));
        }else {
            helper.setImageBitmap(R.id.image_view, BitmapFactory.decodeFile(item.getBgColor()));
        }
        helper.setVisible(R.id.read_bg_iv_checked, item.equals(selected));

    }
}
